<template>
<!-- 接受请求信息时拒绝或接受 -->
  <div class="msg-list">
    <div class="img">
      <img src="@/assets/image/addressImg/head.webp" alt="head">
    </div>
    <div class="desc">
      <span>{{ id }}</span>
      <span>{{ text }}</span>
    </div>
    <div class="select-btn" v-if="!isSelect">
      <van-button
        class="agree-btn"
        type="primary"
        size="small"
        @click="agreeApplyFunc(id)"
        >接受</van-button
      >
      <van-button type="danger" size="small" @click="refuseApplyFunc(id)"
        >拒绝</van-button
      >
    </div>
    <span class="btn-text" v-if="isSelect">{{ btnText }}</span>
  </div>
</template>

<script>
import { mapActions } from "vuex";
import {Toast} from 'vant'

export default {
  data() {
    return {
      isSelect: false,
      btnText: "",
    };
  },
  props: {
    id: String,
    text: String,
  },

  methods: {
    ...mapActions(["agreeApplyFromFriends", "refuseApplyFromFriends"]),
    
    agreeApplyFunc(id) {
      this.isSelect = true;
      this.btnText = "已添加";
      this.agreeApplyFromFriends(id);
      Toast.success('已添加');
    },
    refuseApplyFunc(id) {
      this.isSelect = true;
      this.btnText = "已拒绝";
      this.refuseApplyFromFriends(id);
      Toast.success('已拒绝');
    },
  },
};
</script>

<style lang="scss" scoped>
.msg-list {
  height: 55px;
  width: 100%;
  display: flex;
  flex-direction: row;
  align-items: center;
  line-height: 20px;
  font-size: 12px;
  padding-left: 15px;
  background-color: rgb(24, 24, 24);
  margin-bottom: 5px;

  .img {
    width: 35px;
    height: 35px;
    border-radius: 5px;
    margin-right: 15px;
    background-color: gray;

    img {
      width: 100%;
      height: 100%;
      display: block;
    }
  }

  .desc {
    width: 55%;
    display: flex;
    flex-direction: column;
  }

  .select-btn {
    width: 30%;
    display: flex;
    justify-content: end;

    .agree-btn {
      margin-right: 5px;
    }
  }
  .btn-text {
    display: inline-block;
    width: 30%;
    text-align: center;
  }
}
</style>